<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>商家信息列表</title>
	<link rel="stylesheet" type="text/css" href="<?php echo base_url('data/public/themes/default/easyui.css'); ?>">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url('data/public/themes/icon.css'); ?>">
	<link rel="stylesheet" type="text/css" href="<?php echo base_url('data/public/css/demo.css'); ?>">
	<script type="text/javascript" src="<?php echo base_url('data/public/js/jquery.min.js'); ?>"></script>
	<script type="text/javascript" src="<?php echo base_url('data/public/js/jquery.easyui.min.js'); ?>"></script>
</head>
<body>
	<a href="javascript:void(0)"  style="width:150px" class="easyui-linkbutton" onclick="addAdmin()" data-options="iconCls:'icon-add'">添加管理员</a>
	<div style="margin:10px 0;"></div>
	<div style="margin:10px 11px 0px 0px;">
		<table class="easyui-datagrid" title="管理员信息列表" style="width:1200px;height:600px"
				data-options="singleSelect:true,collapsible:true,url:'datagrid_data1.json',method:'get',fitColumns:true">
			
					<thead>
						<tr>
							<th data-options="field:'id',width:30,align:'center'" >ID号</th>
							<th data-options="field:'login_name',width:30,align:'center'">账号</th>
							<th data-options="field:'status',width:30,align:'center'">状态</th>
							<th data-options="field:'status2',width:40,align:'center'">创建时间</th>
														<th data-options="field:'attr1',width:30,align:'center'">最后登录时间</th>
							<th data-options="field:'status3',width:40,align:'center'">操作</th>							
						</tr>
					</thead>
					<?php foreach ($adminList as $al): ?>
					 <tbody>   
					        <tr>   
					            <td><?php echo $al['id'] ?></td>
					            <td><?php echo $al['username'] ?></td>
					        	<td> 
						        	<?php if($al['status']==0): ?>
						            		禁用
						            	<?php elseif($al['status']==10): ?>
						            		活跃
						            <?php endif; ?>
					        	</td>
					            <td>
						            
					            </td>  
					            <td><?php echo date("Y-m-d H:i:s", $al['created_at']); ?></td>   	
					             <td><a id="btn" href="#" class="easyui-linkbutton" style="width:80px" onclick="update(<?php echo $al['id'] ?>)" data-options="iconCls:'icon-edit'">修改</a>&nbsp;&nbsp;
					            	<a id="btn" href="javascript:void(0)" class="easyui-linkbutton" style="width:80px" onclick="deleteForm(<?php echo $al['id'] ?>)" data-options="iconCls:'icon-edit'">删除</a>
					            </td>	
					        </tr>   
				
			    	</tbody>   
				<?php endforeach?>
		</table>
	</div>

	<div id="dlg" class="easyui-dialog" title="个人信息修改" data-options="iconCls:'icon-save',closed:close" style="width:450px;height:280px;padding:10px">
				<table cellpadding="5" width="400px">
	    		<tr>
	    			<td>账号:</td>
	    			<td><input id='adName' class="easyui-textbox" type="text" style='width:300px;height:20px' name="Business_pwd" data-options="required:true,missingMessage:'请输入密码'"></input></td>
	    		</tr>
	    		<tr>
	    			<td>密码:</td>
	    			<td><input id='adPwd' class="easyui-textbox" type="password" style='width:300px;height:20px' name="Business_name" data-options="required:true,missingMessage:'请输入商家名称'"></input></td>
	    		</tr>
	    		<tr>
	    			<td>确认密码:</td>
	    			<td><input id='adPwdR' class="easyui-textbox" type="password" style='width:300px;height:20px' name="Business_name" data-options="required:true,missingMessage:'请输入商家名称'"></input></td>
	    		</tr>	    		
	    		<tr>
	    			<td>状态:</td>
	    			<td>
	    				<select id='adStatus' class="easyui-combobox" name="state2" style="width:300px;height:20px">
	    					<option value="10">活跃</option>
	    					<option value="0">禁用</option>
	    				</select>
	    			</td>
	    		</tr>	 
	    	</table>

	    	<div style="text-align:center;padding:20px">
		    	<a href="javascript:void(0)"  style="width:100%" class="easyui-linkbutton" onclick="addAdminOk()" data-options="iconCls:'icon-man'">确定添加</a>
	    	</div>
			
	</div>
	<div id="dlg1" class="easyui-dialog" title="个人信息修改" data-options="iconCls:'icon-save',closed:close" style="width:450px;height:270px;padding:10px">
				<table cellpadding="5" width="400px">
	    		<tr>
	    			<td>账号:</td>
	    			<td><input id='adName1' class="easyui-textbox" type="text" style='width:300px;height:20px' name="Business_pwd" data-options="required:true,missingMessage:'请输入密码'"></input></td>
	    		</tr>
	    		<tr>
	    			<td>密码:</td>
	    			<td><input id='adPwd1' class="easyui-textbox" type="password" style='width:300px;height:20px' name="Business_name" data-options="required:true,missingMessage:'请输入商家名称'"></input></td>
	    		</tr>
	    		<tr>
	    			<td>确认密码:</td>
	    			<td><input id='adPwdR1' class="easyui-textbox" type="password" style='width:300px;height:20px' name="Business_name" data-options="required:true,missingMessage:'请输入商家名称'"></input></td>
	    		</tr>	    		
	    		<tr>
	    			<td>状态:</td>
	    			<td>
	    				<select id='adStatus1' class="easyui-combobox" name="state2" style="width:300px;height:20px">
	    					<option value="10">活跃</option>
	    					<option value="0">禁用</option>
	    				</select>
	    			</td>
	    		</tr>	 
	    	</table>

	    	<div style="text-align:center;padding:20px">
		    	<a href="javascript:void(0)"  style="width:100%" class="easyui-linkbutton" onclick="editAdminOk()" data-options="iconCls:'icon-man'">确定修改</a>
	    	</div>
			
	</div>
	
	<input id='editAdid' type="hidden" name="field＿name" value="value">
	<script>
		
	function addAdmin(){
		
		$('#dlg').dialog('open');
	}
	function addAdminOk(){
		
		var adName=document.getElementById("adName").value;
		var adPwd=document.getElementById("adPwd").value;	
		var adPwdR=document.getElementById("adPwdR").value;
		var adStatus=$('#adStatus').combobox('getValue'); 
		
		if(adPwd !=adPwdR)
		{
			$.messager.alert('结果','密码不一致');
			exit();
		}
		$.ajax({
			url : '<?php echo site_url('index.php/backend/Admin/addAdmin') ; ?>',
			type : 'post',
			data : {
				adName:adName,
				adPwd:adPwd,
				adStatus:adStatus
			},
			
			success : function (data, response, status) {
				$.messager.progress('close');
				if(data == 0){
					location.href = '<?php echo site_url('index.php/backend/Admin/adminIndex'); ?>';
				}
				else
				{
					$.messager.alert('结果',data);
				}
			}
		});
		
		
		
	}
	
	
	function deleteForm(str){
		$.extend($.messager.defaults,{  
		    ok:"确定",  
		    cancel:"取消"  
		}); 
		
		$.messager.confirm(	'确认','您确认想要删除记录吗？',function(r){    
		    if (r){    
		    	$.ajax({
					url : '<?php echo site_url('index.php/backend/Admin/deleAdmin') . '/'; ?>'+str,
					type : 'post',
					data : {
						adminId:str,
					},
					
					
					success : function (data, response, status) {
						$.messager.progress('close');
						if(data == 0){
							location.href = '<?php echo site_url('index.php/backend/Admin/adminIndex'); ?>';
						}
						else
						{
							$.messager.alert('结果',data);
						}
					}
				});
		    }    
		});  
	}
	function update(str){
		
		$.ajax({
			url : '<?php echo site_url('index.php/backend/Admin/GetAdminOne') . '/'; ?>'+str,
			type : 'post',
			data : {
				adminId:str
			},
           success : function (data, response, status) {
        	   var strJSON = data; 
				var obj = eval( "(" + strJSON + ")" );
				document.getElementById("adName1").value=obj.username;
				$('#adStatus1').combobox('setValue',obj.status);
				document.getElementById("editAdid").value=obj.id;
				$('#dlg1').dialog('open');
			}
		});
	
	}

	function editAdminOk()
	{
		var editAdid=document.getElementById("editAdid").value;
		var adName1=document.getElementById("adName1").value;
		var adPwd1=document.getElementById("adPwd1").value;	
		var adPwdR1=document.getElementById("adPwdR1").value;
		var adStatus1=$('#adStatus1').combobox('getValue'); 
		if(adPwd1 !=adPwdR1)
		{
			$.messager.alert('结果','密码不一致');
			exit();
		}
		$.ajax({
			url : '<?php echo site_url('index.php/backend/Admin/editAdmin') ; ?>',
			type : 'post',
			data : {
				editAdid:editAdid,
				adName1:adName1,
				adPwd1:adPwd1,
				adStatus1:adStatus1
			},
			
			success : function (data, response, status) {
				$.messager.progress('close');
				if(data == 0){
					location.href = '<?php echo site_url('index.php/backend/Admin/adminIndex'); ?>';
				}
				else
				{
					$.messager.alert('结果',data);
				}
			}
		});
	}
	
	</script>
</body>
</html>